package listeners

import (
	"fmt"
	"github.com/goravel/framework/contracts/event"
	"github.com/goravel/framework/contracts/queue"
	"github.com/goravel/framework/facades"
	"goravel/app/jobs"
)

type SendShipmentNotification struct {
}

func (receiver *SendShipmentNotification) Signature() string {
	return "send_shipment_notification"
}

func (receiver *SendShipmentNotification) Queue(args ...any) event.Queue {
	return event.Queue{
		Enable:     true,
		Connection: "",
		Queue:      "sync",
	}
}

func (receiver *SendShipmentNotification) Handle(args ...any) error {
	device_id := args[0].(string)
	byteStr := args[1].(string)
	fmt.Println("Sending shipment notification to device:", device_id, "with data:", byteStr)
	err := facades.Queue().Job(&jobs.ShipmentJob{}, []queue.Arg{
		{Type: "string", Value: device_id},
		{Type: "uint8", Value: byteStr},
	}).Dispatch()
	if err != nil {
		// do something
	}
	return nil
}
